home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / wb-enhancement / swazblanker / programmer / dev / exampleblanker.c < prev    next >
C/C++ Source or Header  |  1996-02-26  |  8KB  |  330 lines

  1.  
  2.  
  3. /*
  4. **  $VER: Example 2.20 (28.11.95)
  5. **  SwazBlanker Release 2.20
  6. **
  7. **  Example SwazBlanker Module Source
  8. **
  9. **  (C) Copyright 1992-95 David Swasbrook,
  10. **         All Rights Reserved
  11. */
  12.  
  13. /********************************************************************
  14.  
  15.     Well here is some example source for SwazBlanker 2.20
  16.  
  17.     * SB_Init() interface to get invocation method.
  18.  
  19.     * uses "swazconfig.library" support for shared
  20.       configuration file
  21.  
  22.     * Sorry that this source is not 100% documented. Any
  23.       problems please email swaz@ait.ac.nz
  24.  
  25. ********************************************************************/
  26.  
  27.  
  28.     #include <stdio.h>
  29.  
  30.     #include <proto/exec.h>
  31.     #include <proto/dos.h>
  32.     #include <proto/intuition.h>
  33.  
  34.     #include <proto/swazblanker.h>
  35.     #include <proto/swazconfig.h>
  36.     #include <libraries/swazblanker.h>
  37.     #include <libraries/swazconfig.h>
  38.  
  39. /*
  40. ** Setup the library bases we need to open
  41. */
  42.     struct SwazBlankerBase *SwazBlankerBase;
  43.     struct SwazConfigBase *SwazConfigBase;
  44.  
  45. /*
  46. ** Standard version string
  47. */
  48.     #define VERSION           2
  49.     #define REVISION          20
  50.  
  51.     extern UBYTE VersionStr[] = "$VER: ExampleBlanker 2.20 (28.11.95)";
  52.     extern UBYTE NameStr[]    = "ExampleBlanker";
  53.     extern UBYTE Name[]       = "Example";
  54.  
  55. /*
  56. ** SwazBlanker ID string
  57. **
  58. ** The blanker identification string used to be different, i have
  59. ** changed to the new format and now the blanker is run with the
  60. ** argument INFO to query the necessary info... this way it can
  61. ** easily be localized.
  62. **
  63. */
  64. extern UBYTE ID[] = "\0$BLANKER:Ver 2:";
  65.  
  66.  
  67.  
  68. /*
  69. ** SwazBlanker Init Structure
  70. */
  71.     struct SBInit *SBInit;
  72.  
  73.  
  74.     struct BPrefs {
  75.         LONG Option1;
  76.         WORD Option2;
  77.         WORD Option3;
  78.     };
  79.     struct BPrefs BPrefs;
  80.  
  81.  
  82.     #define DEF_OPTION1  57
  83.     #define DEF_OPTION2  127
  84.     #define DEF_OPTION3  33
  85.  
  86.  
  87.     STRPTR CFT[] = {
  88.         "Option1",
  89.         "Option2",
  90.         "Option3",
  91.         NULL
  92.          };
  93.  
  94.     #define CFT_OPTION1   0
  95.     #define CFT_OPTION2   1
  96.     #define CFT_OPTION3   2
  97.  
  98.  
  99. LONG CF_GetNumeric( APTR cf, STRPTR Name, LONG def )
  100. {
  101.     struct SC_ConfigVar *cv;
  102.     STRPTR s;
  103.     LONG v;
  104.  
  105.     s = 0;
  106.     if( cv = SC_FindConfigVar( cf, Name ) )
  107.       s = cv->Data;
  108.     
  109.     if( s ) {
  110.       if( StrToLong( s, &v ) == -1 ) v = def;
  111.     }
  112.     else v = def;
  113.  
  114.     return( v );
  115. }
  116.  
  117. STRPTR FmtNumeric( STRPTR b, LONG v )
  118. {
  119.     sprintf(b,"%ld",v);
  120.     return( b );
  121. }
  122.  
  123. void DefaultPrefs( struct BPrefs *p )
  124. {
  125.     p->Option1 = 0;
  126.     p->Option2 = 1;
  127.     p->Option3 = 2;
  128. }
  129.  
  130. void LoadPrefs( struct BPrefs *p, STRPTR FileName )
  131. {
  132.  
  133.     APTR cf;
  134.  
  135.     DefaultPrefs( p );
  136.  
  137.     if( cf = SC_ReadConfig( FileName, &*Name ) )
  138.     {
  139.       p->Option1  = CF_GetNumeric( cf, CFT[ CFT_OPTION1 ],    DEF_OPTION1 );
  140.       p->Option2  = CF_GetNumeric( cf, CFT[ CFT_OPTION2 ],    DEF_OPTION2 );
  141.       p->Option3  = CF_GetNumeric( cf, CFT[ CFT_OPTION3 ],    DEF_OPTION3 );
  142.  
  143.       SC_FreeConfig( cf );
  144.     }
  145. }
  146.  
  147. void SavePrefs( struct BPrefs *p, STRPTR FileName )
  148. {
  149.     APTR cf;
  150.     UBYTE V[32];
  151.  
  152.     if( cf = SC_ReadConfig( FileName, &*Name ) )
  153.     {
  154.       SC_SetConfigVarByName( cf, CFT[ CFT_OPTION1 ], FmtNumeric( &*V, p->Option1 )  );
  155.       SC_SetConfigVarByName( cf, CFT[ CFT_OPTION2 ], FmtNumeric( &*V, p->Option2 )  );
  156.       SC_SetConfigVarByName( cf, CFT[ CFT_OPTION3 ], FmtNumeric( &*V, p->Option3 )  );
  157.  
  158.       SC_WriteConfig( cf, FileName, &*Name );
  159.       SC_FreeConfig( cf );
  160.     }
  161. }
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169. /****** exampleblanker/Prefs() ***********************************
  170. *
  171. * SYNTAX
  172. *    Prefs()
  173. *
  174. * FUNCTION
  175. *    This is the preferences configuration interface for
  176. *    the blanker.
  177. *
  178. * NOTE
  179. *    Your user-interface should use the same font as set in
  180. *    the SwazBlanker preferences. This can be obtained
  181. *    from the SwazBlanker semaphore ssem->InterfaceFont.
  182. *    This is  pointer to a string, Eg "Helvetica 11".
  183. *
  184. *****************************************************************/
  185. void Prefs(void)
  186. {
  187.     ULONG r;
  188.     struct BlankerPrefsNode *bpn;
  189.     struct EasyStruct es = {
  190.         sizeof(struct EasyStruct),
  191.         0,
  192.         "Example Blanker",
  193.         "No configuration required",
  194.         "Save|Use|Cancel" };
  195.  
  196.     LoadPrefs( &BPrefs, SwazBlankerBase->UseFileName );
  197.  
  198.     if( bpn = SB_AddPrefsTaskTagList( &*NameStr, NULL ) )
  199.     {
  200.         switch( EasyRequest(NULL,&es,NULL,NULL) )
  201.         {
  202.           case 0:    /*** CANCEL ***/
  203.         break;
  204.           case 1:    /*** SAVE ***/
  205.         SavePrefs( &BPrefs, SwazBlankerBase->SaveFileName );
  206.         SavePrefs( &BPrefs, SwazBlankerBase->UseFileName );
  207.         break;
  208.           case 2:    /*** USE ONLY ***/
  209.         SavePrefs( &BPrefs, SwazBlankerBase->UseFileName );
  210.         break;
  211.         }
  212.         SB_RemPrefsTask( bpn );
  213.     }
  214.  
  215. }
  216.  
  217.  
  218.  
  219. /*
  220. ** To do help simply:
  221. **
  222.     APTR   SBHelp=NULL;
  223.  
  224.     SBHelp = SB_HelpTags(
  225.         &*Name,              NULL,
  226.         SBHELP_BlankerPrefs, bpn,
  227.         SBHELP_Directory,    TRUE,        
  228.         TAG_DONE);
  229.        .
  230.        .
  231.        .
  232.  
  233.     SB_HelpClose( SBHelp );
  234.  
  235. */
  236.  
  237. /****** exampleblanker/Blank() ***********************************
  238. *
  239. * SYNTAX
  240. *    Blank()
  241. *
  242. * FUNCTION
  243. *    This is the actual blanker routine.
  244. *
  245. *****************************************************************/
  246. void Blank(void)
  247. {
  248.     struct Screen *screen;
  249.     struct Window *window;
  250.     WORD CSpec[] = { 0,0,0,0, -1 };
  251.  
  252.     screen = SB_OpenScreenTags(
  253.             SA_DisplayID,  0,
  254.             SA_Depth,      1,
  255.             SA_Colors,     &CSpec,
  256.             TAG_DONE);
  257.  
  258.     if(screen)
  259.     {
  260.         window = SB_OpenWindowTags(
  261.                   WA_CustomScreen,screen,
  262.                   TAG_DONE);
  263.  
  264.         if(window)
  265.         {
  266.             SB_SetBlankerScreen( screen, window );    /* Set the blankers screen and window */
  267.             SB_BlankerReady();                        /* Tell SwazBlanker we are working */
  268.  
  269.             Wait(SIGBREAKF_CTRL_C);                   /* Wait for abort signal */
  270.  
  271.             SB_ClrBlankerScreen( screen, window );    /* Restore old screen */
  272.             CloseWindow(window);
  273.         }
  274.         CloseScreen(screen);
  275.     }
  276. }
  277.  
  278. /****************************************************************
  279.  
  280. Please examine this startup code carefully, it has changed from
  281. prior version of the Example.c blanker source code. Please check
  282. the SBInit->Method when your module is invoked.
  283.  
  284. If you choose to use swazconfig.library you may wish to share the
  285. same config file as specified by:
  286.  
  287.       SwazBlankerBase->UseFileName  = env:matrix/SwazBlanker.conf
  288.  
  289.   and SwazBlankerBase->SaveFileName = envarc:matrix/SwazBlanker.conf
  290.  
  291. Use your module name for the name of your data section.
  292.  
  293.  ***************************************************************/
  294. void main (int argc, char **argv)
  295. {
  296.     if( SwazBlankerBase = (struct SwazBlankerBase *) OpenLibrary( "swazblanker.library", 42 ) )
  297.     {
  298.       if( SwazConfigBase = (struct SwazConfigBase *) OpenLibrary( "swazconfig.library", 1 ) )
  299.       {
  300.         if( SBInit = SB_InitTags( SBINIT_Name,"Example", TAG_DONE ) )
  301.         {
  302.           switch( SBInit->Method )
  303.           {
  304.                 case SBINIT_METHOD_BLANK: /* We need to blank the screen */
  305.         LoadPrefs( &BPrefs, SwazBlankerBase->UseFileName );
  306.                     Blank();
  307.                     break;
  308.                 case SBINIT_METHOD_PREFS: /* Need to invoke the preferences editor */
  309.                     Prefs();
  310.                     break;
  311.                 case SBINIT_METHOD_INFO:
  312.         SB_PrintInfoTags( SBInit,
  313.             SBINFO_Author,      "Authors Name (Nick)",
  314.             SBINFO_EMail,       "Author@somesite.amiga.com",
  315.             SBINFO_ShortDesc,   "Very short description",
  316.             SBINFO_LongDesc,    "Long multi line description",
  317.             SBINFO_Version,     VERSION,
  318.             SBINFO_Revision,    REVISION,
  319.         //    SBINFO_Time,        &TimeStr[6],
  320.             SBINFO_CPULoading,  SBINFOLOAD_MEDIUM,
  321.             TAG_DONE );
  322.           }
  323.           SB_FreeInit( SBInit );
  324.         }
  325.         CloseLibrary( (struct Library *) SwazBlankerBase );
  326.       }
  327.       CloseLibrary( (struct Library *) SwazConfigBase );
  328.     }
  329. }
  330.